#include<bits/stdc++.h>
using namespace std;
const int N=2*1e5+10;
int a[N],n,ans;
void dfs(int d,int sum,int r,int b){
    if(d>n){
        ans=max(sum,ans);
        return ;
    }
    if(a[r]==a[d]){ dfs(d,sum+a[r],d,b);dfs(d,sum,a,d);}
    if(a[b]==a[d]){dfs(d,sum+a[b],a,d);dfs(d,sum,d,a);}
}
int main(){
    ios::sync_with_stdio();
    cin.tie(),cout.tie();
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        ans=0;
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        if(n<=100) dfs(1,0,0,0),cout<<ans<<"\n";
        else cout<<0<<"\n";
    }
}


